#include <iostream>
using namespace std;
int main()
{
int a,b,x,i;
while(cin>>a>>b,a!=0||b!=0)
{
x=1;
for(i=1;i<=b;i++)
    x=(a*x)%1000;
cout<<x<<endl;
}
return 0;
}
